################################################################################
### "Voting for Disabled Candidates" by Stefanie Reher, Journal of Politics
### 27 November 2023
################################################################################

################################################################################
### Preparation ################################################################
################################################################################

rm(list=ls())
options(scipen=999)

### Install and load necessary packages 

# If a package is not installed, remove hash to install it

#install.packages("clubSandwich")
library(clubSandwich)
#install.packages("lme4")
library(lme4)
#install.packages("lmerTest")
library(lmerTest)
#install.packages("plm")
library(plm)
#install.packages("lmtest")
library(lmtest)
#install.packages("ggplot2")
library(ggplot2)
#install.packages("ggpubr")
library(ggpubr)
#install.packages("clusterSEs")
library(clusterSEs)
#install.packages("sjPlot")
#install.packages("sjmisc")
library(sjPlot)
library(sjmisc)
#install.packages("miceadds")
library(miceadds)
#install.packages("tibble")
#install.packages("rlang")
library(tibble)
#install.packages("interplot")
library(interplot)
#install.packages("stargazer")
library(stargazer)
#install.packages("mediation")
library(mediation)
#install.packages("effects")
library(effects)

### Create function to generate data frame with estimates from coeftest to create coefficient plots

ctdf <- function(x){
  rt=list()                             # generate empty results list
  for(c in 1:dim(x)[2]) rt[[c]]=x[,c]   # writes column values of x to list
  rt=as.data.frame(rt)                  # converts list to data frame object
  names(rt)=names(x[1,])                # assign correct column names
  rt[,"sig"]=symnum(rt$`Pr(>|z|)`, corr = FALSE, na = FALSE,
        cutpoints = c(0, 0.001, 0.01, 0.05, 0.1, 1),symbols = c("***", "**", "*", ".", " "))
  return(rt)
}

### Set working directory and load data

# setwd: set your own working directory
setwd(" ")
data <- read.csv("data.csv")

### code variables as factors:

data$c.dis <- relevel(as.factor(data$c.dis), ref="None")
data$c.party3 <- as.factor(data$c.party3)

### Set seed for mediation analysis
set.seed(1000)
# Please note: the results of the mediation analyses differ slightly each time the model is run despite setting the seed


################################################################################
### Analysis ###################################################################
################################################################################

### SUPPLEMENTARY INFORMATION (SI) 2: Regressing voter support on candidate disability, 
    # without and with voter ideology interaction (Figure 1)

################################################################################

### Table S2: Effects of candidate disability on voter support (not interacted with voter ideology)

### Model 1: both countries, binary disability measure

vote.s2.m1 <- plm(vote.n ~ c.disdummy + c.age + c.female + c.minority + c.job + c.exp + 
              c.child.num + c.heldoffice + as.factor(candidate) + country, model="p", index="ID", 
              data=subset(data, is.na(c.party)))
vote.s2.m1.coef <- coeftest(vote.s2.m1, vcov=vcovHC(vote.s2.m1, type="HC0", cluster="group"))  
vote.s2.m1.coef
# Apply ctdf function to create data frame
vote.s2.m1.frame=ctdf(vote.s2.m1.coef) 
vote.s2.m1.frame

### Model 2: US, binary disability measure

vote.s2.m2 <- plm(vote.n ~ c.disdummy + c.age + c.female + c.minority + c.job + c.exp + 
              c.child.num + c.heldoffice + as.factor(candidate), model="p", index="ID", 
              data=subset(data, country=="US" & is.na(c.party)))
vote.s2.m2.coef <- coeftest(vote.s2.m2, vcov=vcovHC(vote.s2.m2, type="HC0", cluster="group"))  
# Apply function ctdf
vote.s2.m2.frame=ctdf(vote.s2.m2.coef) 
vote.s2.m2.frame

### Model 3: UK, binary disability measure

vote.s2.m3 <- plm(vote.n ~ c.disdummy + c.age + c.female + c.minority + c.job + c.exp + 
              c.child.num + c.heldoffice + as.factor(candidate), model="p", index="ID", 
              data=subset(data, country=="UK" & is.na(c.party)))
vote.s2.m3.coef <- coeftest(vote.s2.m3, vcov=vcovHC(vote.s2.m3, type="HC0", cluster="group"))  
vote.s2.m3.coef
# Apply function ctdf
vote.s2.m3.frame=ctdf(vote.s2.m3.coef) 
vote.s2.m3.frame

### Model 4: both countries, 4-category disability measure

data$c.dis <- relevel(data$c.dis, ref="None") # set reference category

vote.s2.m4 <- plm(vote.n ~ c.dis + c.age + c.female + c.minority + c.job + c.exp + 
             c.child.num + c.heldoffice + as.factor(candidate) + country, model="p", index="ID", 
             data=subset(data, is.na(c.party)))
vote.s2.m4.coef <- coeftest(vote.s2.m4, vcov=vcovHC(vote.s2.m4, type="HC0", cluster="group"))  
vote.s2.m4.coef

### Model 5: logit model, both countries, binary disability measure

vote.s2.m5 <- glm(vote.n ~ c.disdummy + c.age + c.female + c.minority + c.job + c.exp + 
              c.child.num + c.heldoffice + as.factor(candidate) + country, 
              data=subset(data, is.na(c.party)), family = binomial('logit'))
summary(vote.s2.m5)

# Cluster-bootstrapped p-values for the model, based on respondent ID 
  # (note: this model may take 10 minutes or longer to run)
cluster <- cluster.bs.glm(vote.s2.m5, subset(data, is.na(c.party)), ~ ID, report = T)

################################################################################

### Table S2

stargazer(vote.s2.m1.coef, vote.s2.m2.coef, vote.s2.m3.coef, vote.s2.m4.coef, 
          star.cutoffs = c(0.05, 0.01, 0.001),
          type="html", out="TableS2.doc")

# to get the N for each model (models without clustered SEs): 
stargazer(vote.s2.m1, vote.s2.m2, vote.s2.m3, vote.s2.m4,
          star.cutoffs = c(0.05, 0.01, 0.001),
          type="html", out="TableS2-n.doc")

# logit model: add to TableS2
stargazer(vote.s2.m5, 
          star.cutoffs = c(0.05, 0.01, 0.001),
          type="html", out="TableS2-logit.doc")
# check cluster-bootstrapped p-values in case they need adjustments:
cluster

################################################################################
################################################################################
################################################################################

### SI 2, Table S3: Effects of candidate disability on voter support, interacted 
    # with voter left-right ideology (Figure 1)

### Model 1: both countries, binary disability measure

vote.s3.m1 <- plm(vote.n ~ c.disdummy*lrown.s + c.age + c.female + c.minority + c.job + c.exp + 
              c.child.num + c.heldoffice + as.factor(candidate) + country, 
              model="p", index="ID", data=subset(data, is.na(c.party)))
vote.s3.m1.coef <- coeftest(vote.s3.m1, vcov=vcovHC(vote.s3.m1, type="HC0", cluster="group"))  
vote.s3.m1.frame=ctdf(vote.s3.m1.coef) 
vote.s3.m1.frame

### Model 2: US, binary disability measure (shown in Figure 1)

vote.s3.m2 <- plm(vote.n ~ c.disdummy*lrown.s + c.age + c.female + c.minority + c.job + c.exp + 
                c.child.num + c.heldoffice + as.factor(candidate), model="p", index="ID", 
                data=subset(data, country=="US" & is.na(c.party)))
vote.s3.m2.coef <- coeftest(vote.s3.m2, vcov=vcovHC(vote.s3.m2, type="HC0", cluster="group"))  
vote.s3.m2.coef

# equivalent model which saves estimates in format used by interplot function
vote.s3.m2.plot <- glm.cluster(vote.n ~ c.disdummy*lrown.s + c.age + c.female + 
                  c.minority + c.job + c.exp + c.child.num + c.heldoffice + 
                  as.factor(candidate), cluster="ID", data=subset(data, country=="US" & is.na(c.party)))

### Model 3: UK, binary disability measure (shown in Figure 1)

vote.s3.m3 <- plm(vote.n ~ c.disdummy*lrown.s + c.age + c.female + c.minority + c.job + c.exp + 
              c.child.num + c.heldoffice + as.factor(candidate), model="p", index="ID", 
              data=subset(data, country=="UK" & is.na(c.party)))
vote.s3.m3.coef <- coeftest(vote.s3.m3, vcov=vcovHC(vote.s3.m3, type="HC0", cluster="group"))  
vote.s3.m3.coef

vote.s3.m3.plot <- glm.cluster(vote.n ~ c.disdummy*lrown.s +  c.age + c.female + 
                   c.minority + c.job + c.exp + c.child.num + c.heldoffice + 
                   as.factor(candidate), cluster="ID", data=subset(data, country=="UK" & is.na(c.party)))

################################################################################

### Figure 1: Effects of candidate disability on voter support, moderated by voter ideology

interplot(m = vote.s3.m2.plot$glm_res, var1 = "c.disdummy", var2 = "lrown.s") +
  xlab("Respondent left-right") +
  ylab("Conditional AMCE of disability") +
  theme_bw() + ggtitle("                     US") +
  geom_hline(yintercept = 0, linetype = "dashed") + ylim(-0.3, 0.3)
ggsave("Fig1-US.png", dpi=300)

interplot(m = vote.s3.m3.plot$glm_res, var1 = "c.disdummy", var2 = "lrown.s") +
  xlab("Respondent left-right") +
  ylab("Conditional AMCE of disability") +
  theme_bw() + ggtitle("                     UK") +
  geom_hline(yintercept = 0, linetype = "dashed") + ylim(-0.3, 0.3)
ggsave("Fig1-UK.png", dpi=300)

################################################################################

### Model 4: both countries, 4-category disability measure 

vote.s3.m4 <- plm(vote.n ~ c.dis*lrown.s + c.age + c.female + c.minority + c.job + c.exp + 
              c.child.num + c.heldoffice + as.factor(candidate) + country, 
              model="p", index="ID", data=subset(data, is.na(c.party)))
vote.s3.m4.coef <- coeftest(vote.s3.m4, vcov=vcovHC(vote.s3.m4, type="HC0", cluster="group"))  
vote.s3.m4.coef

### Model 5: US, 4-category disability measure 

vote.s3.m5 <- plm(vote.n ~ c.dis*lrown.s + c.age + c.female + c.minority + c.job + c.exp + 
              c.child.num + c.heldoffice + as.factor(candidate), 
              model="p", index="ID", data=subset(data, is.na(c.party) & country=="US"))
vote.s3.m5.coef <- coeftest(vote.s3.m5, vcov=vcovHC(vote.s3.m5, type="HC0", cluster="group"))  
vote.s3.m5.coef

### Model 6: UK, 4-category disability measure 

vote.s3.m6 <- plm(vote.n ~ c.dis*lrown.s + c.age + c.female + c.minority + c.job + c.exp + 
              c.child.num + c.heldoffice + as.factor(candidate), 
              model="p", index="ID", data=subset(data, is.na(c.party) & country=="UK"))
vote.s3.m6.coef <- coeftest(vote.s3.m6, vcov=vcovHC(vote.s3.m6, type="HC0", cluster="group"))  
vote.s3.m6.coef

################################################################################

### Figure S2: Effects of three candidate disability types on voter support, 
    # moderated by voter ideology, separate for US and UK

vote.s3.m5.plot <- glm.cluster(vote.n ~ c.dis*lrown.s +  c.age + c.female + c.minority + c.job + c.exp + 
                   c.child.num + c.heldoffice + as.factor(candidate), 
                   cluster="ID", data=subset(data, is.na(c.party) & country=="US"))

interplot(m = vote.s3.m5.plot$glm_res, var1 = "c.dis", var2 = "lrown.s") +
  xlab("Respondent left-right") +
  ylab("Conditional AMCE of disability") +
  theme_bw() + ggtitle("                                                                 US") +
  geom_hline(yintercept = 0, linetype = "dashed") + ylim(-0.3, 0.35)
ggsave("FigS2-US.png", dpi=300)

vote.s3.m6.plot <- glm.cluster(vote.n ~ c.dis*lrown.s +  c.age + c.female + c.minority + c.job + c.exp + 
                   c.child.num + c.heldoffice + as.factor(candidate), 
                   cluster="ID", data=subset(data, is.na(c.party) & country=="UK"))
interplot(m = vote.s3.m6.plot$glm_res, var1 = "c.dis", var2 = "lrown.s") +
  xlab("Respondent left-right") +
  ylab("Conditional AMCE of disability") +
  theme_bw() + ggtitle("                                                                 UK") +
  geom_hline(yintercept = 0, linetype = "dashed") + ylim(-0.3, 0.35)
ggsave("FigS2-UK.png", dpi=300)

################################################################################

### Model 7: logit model, both countries, binary disability measure

vote.s3.m7 <- glm(vote.n ~ c.disdummy*lrown.s + c.age + c.female + c.minority + c.job + c.exp + 
                    c.child.num + c.heldoffice + as.factor(candidate) + country, 
                  data=subset(data, is.na(c.party)), family = binomial('logit'))
summary(vote.s3.m7)

cluster.s3.m7 <- cluster.bs.glm(vote.s3.m7, subset(data, is.na(c.party)), ~ ID, report = T)

################################################################################

### Table S3

stargazer(vote.s3.m1.coef, vote.s3.m2.coef, vote.s3.m3.coef,
          vote.s3.m4.coef,
          star.cutoffs = c(0.05, 0.01, 0.001),
          type="html", out="TableS3a.doc")

stargazer(vote.s3.m5.coef, vote.s3.m6.coef,
          star.cutoffs = c(0.05, 0.01, 0.001),
          type="html", out="TableS3b.doc")

# to get the N for each model: 
stargazer(vote.s3.m1, vote.s3.m2, vote.s3.m3,
          vote.s3.m4,
          star.cutoffs = c(0.05, 0.01, 0.001),
          type="html", out="TableS3a-n.doc")

stargazer(vote.s3.m5, vote.s3.m6,
          star.cutoffs = c(0.05, 0.01, 0.001),
          type="html", out="TableS3b-n.doc")

# logit model (add to Table S3)
stargazer(vote.s3.m7, 
          star.cutoffs = c(0.05, 0.01, 0.001),
          type="html", out="TableS3-m7.doc")
# check clustered standard errors:
cluster.s3.m7

################################################################################
################################################################################
################################################################################

### SI 3: Controlling for interactions with potential pre-treatment confounders of voter ideology

### Table S4: Effects of candidate disability on voter support, interacted with voter 
    # left-right ideology and controlling for interactions with voter-level pre-treatment variables

vote.s4 <- plm(vote.n ~ c.disdummy*lrown.s + c.disdummy*age.n + c.disdummy*gender + 
           c.disdummy*edu + c.disdummy*emp1 + c.disdummy*disown + c.age + c.female + 
           c.minority + c.job + c.exp + c.child.num + c.heldoffice + as.factor(candidate) + 
           country , model="p", index="ID", data=subset(data, is.na(c.party)))
vote.s4.coef <- coeftest(vote.s4, vcov=vcovHC(vote.s4, type="HC0", cluster="group"))  
vote.s4.coef

################################################################################

# Table S4 
stargazer(vote.s4.coef,
          star.cutoffs = c(0.05, 0.01, 0.001),
          type="html", out="TableS4.doc")

# to get the N: 
stargazer(vote.s4, 
          star.cutoffs = c(0.05, 0.01, 0.001),
          type="html", out="TableS4-n.doc")


################################################################################
################################################################################
################################################################################

### SI 4: Mediation analysis: effect of candidate disability on voter support, 
    # mediated by perceived candidate ideology 

### Left-wing voters: Table S5, Models 1-3; Table S6 (left)

base.model.l <- lm(vote.n ~ c.disdummy + c.age + c.female + c.minority + c.job + c.exp + 
                   c.child.num + c.heldoffice + as.factor(candidate) + country, 
                 data=subset(data, is.na(c.party) & !is.na(lr.s) & lrcat=="left"))
summary(base.model.l) 

# Model 1
med.fit.l <- lm(lr.s ~ c.disdummy + c.age + c.female + c.minority + c.job + c.exp + 
                c.child.num + c.heldoffice + as.factor(candidate) + country, 
              data=subset(data, is.na(c.party) & !is.na(vote.n) & lrcat=="left"))
summary(med.fit.l)

# Model 2
out.fit.lm.l <- lm(vote.n ~ lr.s + c.disdummy + c.age + c.female + c.minority + c.job + c.exp + 
                c.child.num + c.heldoffice + as.factor(candidate) + country,  
              data=subset(data, is.na(c.party) & lrcat=="left"))
summary(out.fit.lm.l)

# Results from mediation analysis need to be entered into Table S6 manually. 
  # The p-values reported in the text are taken from these results. This code 
  # generates the results for left-wing voters for the linear model:
med.out.l <- mediate(med.fit.l, out.fit.lm.l, treat = "c.disdummy", mediator = "lr.s",
                   robustSE = T, sims = 10000)
summary(med.out.l)

################################################################################

### Figure S3: Sensitivity analysis for sequential ignorability assumption (left plot)

sens.out.l <- medsens(med.out.l, rho.by = 0.1, effect.type = "indirect", sims = 100)
summary(sens.out.l)
png(file="FigureS3-left.png")
plot(sens.out.l, sens.par = "rho", main = "Left-wing voters", ylim = c(-0.2, 0.2))
dev.off()

################################################################################

### Table S5, Model 3: logit model

out.fit.ln.l <- glm(vote.n ~ lr.s + c.disdummy + c.age + c.female + c.minority + c.job + c.exp + 
                     c.child.num + c.heldoffice + as.factor(candidate) + country,  
                   data=subset(data, is.na(c.party) & lrcat=="left"), family = binomial('logit'))
summary(out.fit.ln.l)

# Results from mediation analysis need to be entered into Table S6 manually. 
# The p-values reported in the text are taken from these results. This code 
# generates the results for left-wing voters for the logit model:
med.out.ln.l <- mediate(med.fit.l, out.fit.ln.l, treat = "c.disdummy", mediator = "lr.s",
                   robustSE = T, sims = 10000)
summary(med.out.ln.l)

################################################################################

### Table S5 (left-wing voters models): 

stargazer(med.fit.l, out.fit.lm.l, out.fit.ln.l,
          star.cutoffs = c(0.05, 0.01, 0.001),
          type="html", out="TableS5a.doc")

################################################################################
################################################################################

### Right-wing voters: Table S5, Models 4-5; Table S6

base.model.r <- lm(vote.n ~ c.disdummy + c.age + c.female + c.minority + c.job + c.exp + 
                c.child.num + c.heldoffice + as.factor(candidate) + country, 
                data=subset(data, is.na(c.party) & !is.na(lr.s) & lrcat=="right"))
summary(base.model.r) 

# Model 4:
med.fit.r <- lm(lr.s ~ c.disdummy + c.age + c.female + c.minority + c.job + c.exp + 
             c.child.num + c.heldoffice + as.factor(candidate) + country, 
             data=subset(data, is.na(c.party) & !is.na(vote.n) & lrcat=="right"))
summary(med.fit.r)

# Model 5:
out.fit.lm.r <- lm(vote.n ~ lr.s + c.disdummy + c.age + c.female + c.minority + c.job + c.exp + 
                c.child.num + c.heldoffice + as.factor(candidate) + country,  
                data=subset(data, is.na(c.party) & lrcat=="right"))
summary(out.fit.lm.r)

# Results from mediation analysis need to be entered into Table S6 manually. 
# The p-values reported in the text are taken from these results. This code 
# generates the results for right-wing voters for the linear model:

med.out.lm.r <- mediate(med.fit.r, out.fit.lm.r, treat = "c.disdummy", mediator = "lr.s",
                   robustSE = T, sims = 10000)
summary(med.out.lm.r)

################################################################################

### Figure S3: Sensitivity analysis for sequential ignorability assumption (right plot)

sens.out.r <- medsens(med.out.lm.r, rho.by = 0.1, effect.type = "indirect", sims = 100)
summary(sens.out.r)
png(file="FigureS3-right.png")
plot(sens.out.r, sens.par = "rho", main = "Right-wing voters", ylim = c(-0.2, 0.2))
dev.off()

################################################################################

### Table S5, Model 6: logit model

out.fit.ln.r <- glm(vote.n ~ lr.s + c.disdummy + c.age + c.female + c.minority + c.job + c.exp + 
                c.child.num + c.heldoffice + as.factor(candidate) + country,  
                data=subset(data, is.na(c.party) & lrcat=="right"), family = binomial('logit'))
summary(out.fit.ln.r)

# Results from mediation analysis need to be entered into Table S6 manually. 
# The p-values reported in the text are taken from these results. This code 
# generates the results for right-wing voters for the logit model:
med.out.ln.r <- mediate(med.fit.r, out.fit.ln.r, treat = "c.disdummy", mediator = "lr.s",
                       robustSE = T, sims = 10000)
summary(med.out.ln.r)

################################################################################

### Table S5 (right-wing voters models): 

stargazer(med.fit.r, out.fit.lm.r, out.fit.ln.r,
          star.cutoffs = c(0.05, 0.01, 0.001),
          type="html", out="tableS5b.doc")

################################################################################
################################################################################

### Analysis by country 

### US (Table S7, Table S9)

# Left-wing voters 

base.model.usl <- lm(vote.n ~ c.disdummy + c.age + c.female + c.minority + c.job + c.exp + 
                  c.child.num + c.heldoffice + as.factor(candidate), 
                  data=subset(data, country=="US" & is.na(c.party) & !is.na(lr.s) & lrcat=="left"))
summary(base.model.usl) 

# Model 1:
med.fit.usl <- lm(lr.s ~ c.disdummy + c.age + c.female + c.minority + c.job + c.exp + 
               c.child.num + c.heldoffice + as.factor(candidate) , 
               data=subset(data, country=="US" & is.na(c.party) & !is.na(vote.n) & lrcat=="left"))
summary(med.fit.usl)

# Model 2:
out.fit.usl <- lm(vote.n ~ lr.s + c.disdummy + c.age + c.female + c.minority + c.job + c.exp + 
               c.child.num + c.heldoffice + as.factor(candidate) ,  
               data=subset(data, country=="US" & is.na(c.party) & lrcat=="left"))
summary(out.fit.usl)

# Results from mediation analysis need to be added to Table S9 manually. This code generates the 
  # results for left-wing voters in the US:
med.out.usl <- mediate(med.fit.usl, out.fit.usl, treat = "c.disdummy", mediator = "lr.s",
               robustSE = T, sims = 10000)
summary(med.out.usl)


# Right-wing voters 

base.model.usr <- lm(vote.n ~ c.disdummy + c.age + c.female + c.minority + c.job + c.exp + 
                  c.child.num + c.heldoffice + as.factor(candidate), 
                  data=subset(data, country=="US" & is.na(c.party) & !is.na(lr.s) & lrcat=="right"))
summary(base.model.usr) 

# Model 3:
med.fit.usr <- lm(lr.s ~ c.disdummy + c.age + c.female + c.minority + c.job + c.exp + 
             c.child.num + c.heldoffice + as.factor(candidate) , 
             data=subset(data, country=="US" & is.na(c.party) & !is.na(vote.n) & lrcat=="right"))
summary(med.fit.usr)

# Model 4:
out.fit.usr <- lm(vote.n ~ lr.s + c.disdummy + c.age + c.female + c.minority + c.job + c.exp + 
               c.child.num + c.heldoffice + as.factor(candidate) ,  
               data=subset(data, country=="US" & is.na(c.party) & lrcat=="right"))
summary(out.fit.usr)

# Results from mediation analysis need to be added to Table S9 manually. This code generates the 
# results for right-wing voters in the US:
med.out.usr <- mediate(med.fit.usr, out.fit.usr, treat = "c.disdummy", mediator = "lr.s",
               robustSE = T, sims = 10000)
summary(med.out.usr)

# Table S7: 

stargazer(med.fit.usl, out.fit.usl, med.fit.usr, out.fit.usr,
          star.cutoffs = c(0.05, 0.01, 0.001),
          type="html", out="TableS7.doc")

################################################################################
################################################################################

### UK (Table S8, Table S9)

# Left-wing voters 

base.model.ukl <- lm(vote.n ~ c.disdummy + c.age + c.female + c.minority + c.job + c.exp + 
                  c.child.num + c.heldoffice + as.factor(candidate), 
                  data=subset(data, country=="UK" & is.na(c.party) & !is.na(lr.s) & lrcat=="left"))
summary(base.model.ukl) 

# Model 1
med.fit.ukl <- lm(lr.s ~ c.disdummy + c.age + c.female + c.minority + c.job + c.exp + 
               c.child.num + c.heldoffice + as.factor(candidate) , 
               data=subset(data, country=="UK" & is.na(c.party) & !is.na(vote.n) & lrcat=="left"))
summary(med.fit.ukl)

# Model 2
out.fit.ukl <- lm(vote.n ~ lr.s + c.disdummy + c.age + c.female + c.minority + c.job + c.exp + 
               c.child.num + c.heldoffice + as.factor(candidate) ,  
               data=subset(data, country=="UK" & is.na(c.party) & lrcat=="left"))
summary(out.fit.ukl)

# Results from mediation analysis need to be added to Table S9 manually. This code generates the 
# results for left-wing voters in the UK:
med.out.ukl <- mediate(med.fit.ukl, out.fit.ukl, treat = "c.disdummy", mediator = "lr.s",
                     robustSE = T, sims = 10000)
summary(med.out.ukl)

# Right-wing voters 

base.model.ukr <- lm(vote.n ~ c.disdummy + c.age + c.female + c.minority + c.job + c.exp + 
                     c.child.num + c.heldoffice + as.factor(candidate), 
                   data=subset(data, country=="UK" & is.na(c.party) & !is.na(lr.s) & lrcat=="right"))
summary(base.model.ukr) ## not for mediation analysis - just to see total effect size

# Model 3
med.fit.ukr <- lm(lr.s ~ c.disdummy + c.age + c.female + c.minority + c.job + c.exp + 
                  c.child.num + c.heldoffice + as.factor(candidate) , 
                data=subset(data, country=="UK" & is.na(c.party) & !is.na(vote.n) & lrcat=="right"))
summary(med.fit.ukr)

# Model 4
out.fit.ukr <- lm(vote.n ~ lr.s + c.disdummy + c.age + c.female + c.minority + c.job + c.exp + 
                  c.child.num + c.heldoffice + as.factor(candidate) ,  
                data=subset(data, country=="UK" & is.na(c.party) & lrcat=="right"))
summary(out.fit.ukr)

# Results from mediation analysis need to be added to Table S9 manually. This code generates the 
# results for right-wing voters in the UK:
med.out.ukr <- mediate(med.fit.ukr, out.fit.ukr, treat = "c.disdummy", mediator = "lr.s",
                     robustSE = T, sims = 10000)
summary(med.out.ukr)

# Table S8

stargazer(med.fit.ukl, out.fit.ukl, med.fit.ukr, out.fit.ukr,
          star.cutoffs = c(0.05, 0.01, 0.001),
          type="html", out="TableS8.doc")

################################################################################
################################################################################
################################################################################

### SI 5: Effects of information about candidates’ party affiliation on perceived 
    # ideology and voter support (Figures 2 and 3)

### Table S10: Effects of candidate disability on perceived candidate ideology, 
    # interacted with party affiliation treatment (Models 2 and 3 shown in Figure 2)

### Model 1: All voters 

data$c.party3 <- relevel(data$c.party3, ref = "No party") 
lr1 <- plm(lr.s ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
          c.child.num + c.heldoffice + as.factor(candidate) + country, model="p", index="ID", 
          data=data)
lr1.coef <- coeftest(lr1, vcov=vcovHC(lr1, type="HC0", cluster="group"))  
lr1.frame=ctdf(lr1.coef) 

### Model 2: Left-wing voters 

# Estimate model  with each level of candidate party as reference category to get 
# estimates for the figure

# These are the estimates in the table:
data$c.party3 <- relevel(data$c.party3, ref = "No party") # need to change ref cat
lr1.l <- plm(lr.s ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
         c.child.num + c.heldoffice + as.factor(candidate) + country, model="p", index="ID", 
         data=subset(data, lrcat=="left"))
lr1.l.coef <- coeftest(lr1.l, vcov=vcovHC(lr1.l, type="HC0", cluster="group"))  
lr1.l.frame=ctdf(lr1.l.coef) 

data$c.party3 <- relevel(data$c.party3, ref = "Left") # need to change ref cat
lr2.l <- plm(lr.s ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
         c.child.num + c.heldoffice + as.factor(candidate) + country, model="p", index="ID", 
         data=subset(data, lrcat=="left"))
lr2.l.coef <- coeftest(lr2.l, vcov=vcovHC(lr2.l, type="HC0", cluster="group"))  
lr2.l.frame=ctdf(lr2.l.coef) 

data$c.party3 <- relevel(data$c.party3, ref = "Right") # need to change ref cat
lr3.l <- plm(lr.s ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
         c.child.num + c.heldoffice + as.factor(candidate) + country, model="p", index="ID", 
         data=subset(data, lrcat=="left"))
lr3.l.coef <- coeftest(lr3.l, vcov=vcovHC(lr3.l, type="HC0", cluster="group"))  
lr3.l.frame=ctdf(lr3.l.coef) 

### Model 3: Right-wing voters

# These are the estimates in the table:
data$c.party3 <- relevel(data$c.party3, ref = "No party") 
lr1.r <- plm(lr.s ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
         c.child.num + c.heldoffice + as.factor(candidate) + country, model="p", index="ID", 
         data=subset(data, lrcat=="right"))
lr1.r.coef <- coeftest(lr1.r, vcov=vcovHC(lr1.r, type="HC0", cluster="group"))  
lr1.r.frame=ctdf(lr1.r.coef) 

data$c.party3 <- relevel(data$c.party3, ref = "Left")
lr2.r <- plm(lr.s ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
         c.child.num + c.heldoffice + as.factor(candidate) + country, model="p", index="ID", 
         data=subset(data, lrcat=="right"))
lr2.r.coef <- coeftest(lr2.r, vcov=vcovHC(lr2.r, type="HC0", cluster="group"))  
lr2.r.frame=ctdf(lr2.r.coef) 

data$c.party3 <- relevel(data$c.party3, ref = "Right") 
lr3.r <- plm(lr.s ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
         c.child.num + c.heldoffice + as.factor(candidate) + country, model="p", index="ID", 
         data=subset(data, lrcat=="right"))
lr3.r.coef <- coeftest(lr3.r, vcov=vcovHC(lr3.r, type="HC0", cluster="group"))  
lr3.r.frame=ctdf(lr3.r.coef) 

################################################################################

### Figure 2: Effect of candidate disability on voter support among left-wing and 
    # right-wing voters, moderated by candidates’ party affiliation 

# Figure 2a (plot on the left in Figure 2):Effect on perceived candidate ideology; 
  # needs to be merged with Figure 2b below. Figure plots estimates from Models 2 and 3.

# Coefficient plot
t1.labels <- c("Sample", "Party", "Coefficient", "SE")
t1.row1 <- c("Left-wing voters", "No party", lr1.l.frame[2,1], lr1.l.frame[2,2] )
t1.row2 <- c("Left-wing voters", "Left party", lr2.l.frame[2,1], lr2.l.frame[2,2] )
t1.row3 <- c("Left-wing voters","Right party", lr3.l.frame[2,1], lr3.l.frame[2,2] )
t1.row4 <- c("Right-wing voters", "No party", lr1.r.frame[2,1], lr1.r.frame[2,2] )
t1.row5 <- c("Right-wing voters", "Left party", lr2.r.frame[2,1], lr2.r.frame[2,2] )
t1.row6 <- c("Right-wing voters","Right party", lr3.r.frame[2,1], lr3.r.frame[2,2] )

t1 <- data.frame(rbind(t1.row1,t1.row2,t1.row3,t1.row4,t1.row5,t1.row6))
names(t1) <- t1.labels
t1$Coefficient <- as.numeric(as.character(t1$Coefficient))
t1$SE <- as.numeric(as.character(t1$SE))
t1$Party <- factor(t1$Party, levels = c("Right party", "Left party", "No party"))

interval <- 1.96  # 95% multiplier
plot <- ggplot(t1, aes(shape = Sample))
plot <- plot + geom_hline(yintercept = 0, colour = gray(1/2), lty = 2)
plot <- plot + geom_pointrange(aes(x = Party, y = Coefficient, ymin = Coefficient - SE*interval,
                                   ymax = Coefficient + SE*interval, colour=Sample),
                               lwd = 1/2, shape=20, position = position_dodge(width = 1/2),
                               fill = "WHITE")
plot <- plot +  theme_bw() + ggtitle("Effect on perceived candidate ideology") +
  xlab(" ") + ylab("Conditional AMCE of disability") + ylim(-0.1, 0.1) + coord_flip()
print(plot + scale_colour_manual(name="Sample", values = c("black", "gray45", "gray80")))
ggsave("Fig2a.png", dpi=300) 

# Note: This is the left-hand part of Figure 2; it needs to be merged with the right-hand part 
# (Fig2b) below.

################################################################################

### Table S10

stargazer(lr1.coef, lr1.l.coef, lr1.r.coef,
          star.cutoffs = c(0.05, 0.01, 0.001),
          type="html", out="TableS10.doc")

# table to get N
stargazer(lr1, lr1.l, lr1.r,
          star.cutoffs = c(0.05, 0.01, 0.001),
          type="html", out="TableS10-n.doc")

################################################################################

### Figure S4: Predicted values of perceived candidate ideology, by candidate party and voter ideology

# Redo Models 2 and 3 from above using glm() function in order to use plot_model() function

data$candidate.f <- as.factor(data$candidate) # can't have as.factor in model to use ggeffects

# Model 2: Left-wing voters

lr.l <- glm(lr.s ~ Disability*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
        c.child.num + c.heldoffice + candidate.f + country, 
        data=subset(data, lrcat=="left"))

plot <- plot_model(lr.l, type = "eff", terms = c("c.party3", "Disability"), 
                   dot.size = 2, ci.style = c("bar"), dodge = 0.5) +
  xlab("Candidate party") +  ylab("Perceived candidate ideology") + 
  ggtitle("Predicted perceived candidate \nideology among left-wing voters")  +
  theme_bw() + ylim(0.2, 0.8) + coord_flip() +
  scale_colour_manual(values = c("black", "gray45")) 
plot
ggsave("FigS4left.png", dpi=300)

# right-wing voters
lr.r <- glm(lr.s ~ Disability*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
        c.child.num + c.heldoffice + candidate.f + country, 
        data=subset(data, lrcat=="right"))

plot <- plot_model(lr.r, type = "eff", terms = c("c.party3", "Disability"), 
                   dot.size = 2, ci.style = c("bar"), dodge = 0.5) +
  xlab("Candidate party") +  ylab("Perceived candidate ideology") + 
  ggtitle("Predicted perceived candidate \nideology among right-wing voters")  +
  theme_bw() + ylim(0.2, 0.8) + coord_flip() +
  scale_colour_manual(values = c("black", "gray45")) 
plot
ggsave("FigS4-right.png", dpi=300)

################################################################################
################################################################################

#### Table S11: Effects of candidate disability on voter support, interacted with 
     # party affiliation treatment (Models 1 and 3 shown in Figure 2)

### Model 1: Left-wing voters, OLS

# Estimate model with each party level as reference category to produce figure

# These are the estimates in the table:
data$c.party3 <- relevel(data$c.party3, ref = "No party")
vote.l1 <- plm(vote.n ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
           c.child.num + c.heldoffice + as.factor(candidate) + country, 
           model="p", index="ID", data=subset(data, lrcat=="left"))
vote.l1.coef <- coeftest(vote.l1, vcov=vcovHC(vote.l1, type="HC0", cluster="group"))  
vote.l1.frame=ctdf(vote.l1.coef) 

data$c.party3 <- relevel(data$c.party3, ref = "Left") 
vote.l2 <- plm(vote.n ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
           c.child.num + c.heldoffice + as.factor(candidate) + country, 
           model="p", index="ID", data=subset(data, lrcat=="left"))
vote.l2.coef <- coeftest(vote.l2, vcov=vcovHC(vote.l2, type="HC0", cluster="group"))  
vote.l2.frame=ctdf(vote.l2.coef)

data$c.party3 <- relevel(data$c.party3, ref = "Right")
vote.l3 <- plm(vote.n ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
           c.child.num + c.heldoffice + as.factor(candidate) + country, 
           model="p", index="ID", data=subset(data, lrcat=="left"))
vote.l3.coef <- coeftest(vote.l3, vcov=vcovHC(vote.l3, type="HC0", cluster="group"))  
vote.l3.frame=ctdf(vote.l3.coef)

### Model 2: Left-wing voters, logistic regression

data$c.party3 <- relevel(data$c.party3, ref = "No party") # need to change ref cat
vote.l1.cluster <- glm(vote.n ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
                   c.child.num + c.heldoffice + as.factor(candidate) + country, 
                   data=subset(data, lrcat=="left"), family = binomial('logit'))
# Cluster-bootstrapped p-values for the model, based on respondent ID 
# (note: this model may take 10 minutes or longer to run)
clust.bs.l1 <- cluster.bs.glm(vote.l1.cluster, subset(data, lrcat=="left"), ~ ID, report = T)

### Model 3: Right-wing voters, OLS

# These are the estimates in the table:
data$c.party3 <- relevel(data$c.party3, ref = "No party") # need to change ref cat
vote.r1 <- plm(vote.n ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
           c.child.num + c.heldoffice + as.factor(candidate) + country, 
           model="p", index="ID", data=subset(data, lrcat=="right"))
vote.r1.coef <- coeftest(vote.r1, vcov=vcovHC(vote.r1, type="HC0", cluster="group"))  
vote.r1.frame=ctdf(vote.r1.coef) 

data$c.party3 <- relevel(data$c.party3, ref = "Left") # need to change ref cat
vote.r2 <- plm(vote.n ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
           c.child.num + c.heldoffice + as.factor(candidate) + country, 
           model="p", index="ID", data=subset(data, lrcat=="right"))
vote.r2.coef <- coeftest(vote.r2, vcov=vcovHC(vote.r2, type="HC0", cluster="group"))  
vote.r2.frame=ctdf(vote.r2.coef)

data$c.party3 <- relevel(data$c.party3, ref = "Right") # need to change ref cat
vote.r3 <- plm(vote.n ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
           c.child.num + c.heldoffice + as.factor(candidate) + country, 
           model="p", index="ID", data=subset(data, lrcat=="right"))
vote.r3.coef <- coeftest(vote.r3, vcov=vcovHC(vote.r3, type="HC0", cluster="group"))  
vote.r3.frame=ctdf(vote.r3.coef)

### Model 4: Right-wing voters, logistic regression

data$c.party3 <- relevel(data$c.party3, ref = "No party") # need to change ref cat
vote.r1.cluster <- glm(vote.n ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
                   c.child.num + c.heldoffice + as.factor(candidate) + country, 
                   data=subset(data, lrcat=="right"), family = binomial('logit'))
# Cluster-bootstrapped p-values for the model, based on respondent ID 
# (note: this model may take 10 minutes or longer to run)
clust.bs.r1 <- cluster.bs.glm(vote.r1.cluster, subset(data, lrcat=="right"), ~ ID, report = T)

################################################################################

### Figure 2: Effect of candidate disability on voter support among left-wing and 
# right-wing voters, moderated by candidates’ party affiliation 

# Figure 2b (plot on the right in Figure 2): Effect on perceived candidate ideology; 
# needs to be merged with Figure 2a above. Figure plots estimates from Models 2 and 3 above.

t1.labels <- c("Sample", "Party", "Coefficient", "SE")
t1.row1 <- c("Left-wing voters", "No party", vote.l1.frame[2,1], vote.l1.frame[2,2] )
t1.row2 <- c("Left-wing voters", "Left party", vote.l2.frame[2,1], vote.l2.frame[2,2] )
t1.row3 <- c("Left-wing voters","Right party", vote.l3.frame[2,1], vote.l3.frame[2,2] )
t1.row4 <- c("Right-wing voters", "No party", vote.r1.frame[2,1], vote.r1.frame[2,2] )
t1.row5 <- c("Right-wing voters", "Left party", vote.r2.frame[2,1], vote.r2.frame[2,2] )
t1.row6 <- c("Right-wing voters","Right party", vote.r3.frame[2,1], vote.r3.frame[2,2] )

t1 <- data.frame(rbind(t1.row1,t1.row2,t1.row3,t1.row4,t1.row5,t1.row6))
names(t1) <- t1.labels
t1$Coefficient <- as.numeric(as.character(t1$Coefficient))
t1$SE <- as.numeric(as.character(t1$SE))
t1$Party <- factor(t1$Party, levels = c("Right party", "Left party", "No party"))

interval <- 1.96  # 95% multiplier
plot <- ggplot(t1, aes(shape = Sample))
plot <- plot + geom_hline(yintercept = 0, colour = gray(1/2), lty = 2)
plot <- plot + geom_pointrange(aes(x = Party, y = Coefficient, ymin = Coefficient - SE*interval,
                                   ymax = Coefficient + SE*interval, colour=Sample),
                               lwd = 1/2, shape=20, position = position_dodge(width = 1/2),
                               fill = "WHITE")
plot <- plot +  theme_bw() + ggtitle("Effect on candidate support") +
  xlab(" ") + ylab("Conditional AMCE of disability") + ylim(-0.15, 0.15) + coord_flip()
print(plot + scale_colour_manual(name="Sample", values = c("black", "gray45", "gray80")))
ggsave("Fig2b.png", dpi=300)

################################################################################

### Figure S5: Predicted values of candidate support, by candidate party and voter ideology

# Redo Models 2 and 3 from above using glm() function in order to use plot_model() function

vote.l <- glm(vote.n ~ Disability*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
          c.child.num + c.heldoffice + candidate.f + country, data=subset(data, lrcat=="left"))

plot <- plot_model(vote.l, type = "eff", terms = c("c.party3", "Disability"), 
                   dot.size = 2, ci.style = c("bar"), dodge = 0.5) +
  xlab("Candidate party") +  ylab("Predicted candidate support") + 
  ggtitle("Predicted candidate support \namong left-wing voters")  +
  theme_bw() + ylim(0, 1) + coord_flip() +
  scale_colour_manual(values = c("black", "gray45")) 
plot
ggsave("FigS5left.png", dpi=300)

vote.r <- glm(vote.n ~ Disability*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
          c.child.num + c.heldoffice + candidate.f + country, data=subset(data, lrcat=="right"))

plot <- plot_model(vote.r, type = "eff", terms = c("c.party3", "Disability"), 
                   dot.size = 2, ci.style = c("bar"), dodge = 0.5) +
  xlab("Candidate party") +  ylab("Predicted candidate support") + 
  ggtitle("Predicted candidate support \namong right-wing voters")  +
  theme_bw() + ylim(0, 1) + coord_flip() +
  scale_colour_manual(values = c("black", "gray45")) 
plot
ggsave("FigS5right.png", dpi=300)

################################################################################

### Table S11

stargazer(vote.l1.coef, vote.r1.coef,
          star.cutoffs = c(0.05, 0.01, 0.001),
          type="html", out="TableS11.doc")
# to get N
stargazer(vote.l1, vote.r1,
          star.cutoffs = c(0.05, 0.01, 0.001),
          type="html", out="TableS11-n.doc")
# Logit models - add to Table S11
stargazer(vote.l1.cluster, vote.r1.cluster,
          star.cutoffs = c(0.05, 0.01, 0.001),
          type="html", out="TableS11-logit.doc")

################################################################################
################################################################################

# Analysis by country

### Table S12: Effects of candidate disability on perceived candidate ideology, 
    # interacted with party affiliation treatment, US and UK separately 

### Model 1: US; Left-wing voters 

# Estimate model for each reference category of c.party3

# These are the estimates in the table:
data$c.party3 <- relevel(data$c.party3, ref = "No party") 
lr1.lus <- plm(lr.s ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
           c.child.num + c.heldoffice + as.factor(candidate) , model="p", index="ID", 
           data=subset(data, country=="US" & lrcat=="left"))
lr1.lus.coef <- coeftest(lr1.lus, vcov=vcovHC(lr1.lus, type="HC0", cluster="group"))  
lr1.lus.frame=ctdf(lr1.lus.coef) 

data$c.party3 <- relevel(data$c.party3, ref = "Left") 
lr2.lus <- plm(lr.s ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
           c.child.num + c.heldoffice + as.factor(candidate) , model="p", index="ID", 
           data=subset(data, country=="US" & lrcat=="left"))
lr2.lus.coef <- coeftest(lr2.lus, vcov=vcovHC(lr2.lus, type="HC0", cluster="group"))  
lr2.lus.frame=ctdf(lr2.lus.coef) 

data$c.party3 <- relevel(data$c.party3, ref = "Right") 
lr3.lus <- plm(lr.s ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
           c.child.num + c.heldoffice + as.factor(candidate) , model="p", index="ID", 
           data=subset(data, country=="US" &  lrcat=="left"))
lr3.lus.coef <- coeftest(lr3.lus, vcov=vcovHC(lr3.lus, type="HC0", cluster="group"))  
lr3.lus.frame=ctdf(lr3.lus.coef)

### Model 2: US; Right-wing voters

# These are the estimates in the table:
data$c.party3 <- relevel(data$c.party3, ref = "No party") 
lr1.rus <- plm(lr.s ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
           c.child.num + c.heldoffice + as.factor(candidate) , model="p", index="ID", 
           data=subset(data, country=="US" & lrcat=="right"))
lr1.rus.coef <- coeftest(lr1.rus, vcov=vcovHC(lr1.rus, type="HC0", cluster="group"))  
lr1.rus.frame=ctdf(lr1.rus.coef) 

data$c.party3 <- relevel(data$c.party3, ref = "Right") 
lr2.rus <- plm(lr.s ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
           c.child.num + c.heldoffice + as.factor(candidate) , model="p", index="ID", 
           data=subset(data, country=="US" & lrcat=="right"))
lr2.rus.coef <- coeftest(lr2.rus, vcov=vcovHC(lr2.rus, type="HC0", cluster="group"))  
lr2.rus.frame=ctdf(lr2.rus.coef) 

data$c.party3 <- relevel(data$c.party3, ref = "Right") 
lr3.rus <- plm(lr.s ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
           c.child.num + c.heldoffice + as.factor(candidate) , model="p", index="ID", 
           data=subset(data, country=="US" &  lrcat=="right"))
lr3.rus.coef <- coeftest(lr3.rus, vcov=vcovHC(lr3.rus, type="HC0", cluster="group"))  
lr3.rus.frame=ctdf(lr3.rus.coef)

### Model 3: UK; Left-wing voters 

# These are the estimates in the table:
data$c.party3 <- relevel(data$c.party3, ref = "No party") 
lr1.luk <- plm(lr.s ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
           c.child.num + c.heldoffice + as.factor(candidate) , model="p", index="ID", 
           data=subset(data, country=="UK" & lrcat=="left"))
lr1.luk.coef <- coeftest(lr1.luk, vcov=vcovHC(lr1.luk, type="HC0", cluster="group"))  
lr1.luk.frame=ctdf(lr1.luk.coef) 

data$c.party3 <- relevel(data$c.party3, ref = "Left")
lr2.luk <- plm(lr.s ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
           c.child.num + c.heldoffice + as.factor(candidate) , model="p", index="ID", 
           data=subset(data, country=="UK" & lrcat=="left"))
lr2.luk.coef <- coeftest(lr2.luk, vcov=vcovHC(lr2.luk, type="HC0", cluster="group"))  
lr2.luk.frame=ctdf(lr2.luk.coef) 

data$c.party3 <- relevel(data$c.party3, ref = "Right") 
lr3.luk <- plm(lr.s ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
           c.child.num + c.heldoffice + as.factor(candidate) , model="p", index="ID", 
           data=subset(data, country=="UK" &  lrcat=="left"))
lr3.luk.coef <- coeftest(lr3.luk, vcov=vcovHC(lr3.luk, type="HC0", cluster="group"))  
lr3.luk.frame=ctdf(lr3.luk.coef)

### Model 4: UK; Right-wing voters

# These are the estimates in the table:
data$c.party3 <- relevel(data$c.party3, ref = "No party")
lr1.ruk <- plm(lr.s ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
           c.child.num + c.heldoffice + as.factor(candidate) , model="p", index="ID", 
           data=subset(data, country=="UK" & lrcat=="right"))
lr1.ruk.coef <- coeftest(lr1.ruk, vcov=vcovHC(lr1.ruk, type="HC0", cluster="group"))  
lr1.ruk.frame=ctdf(lr1.ruk.coef) 

data$c.party3 <- relevel(data$c.party3, ref = "Right") 
lr2.ruk <- plm(lr.s ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
           c.child.num + c.heldoffice + as.factor(candidate) , model="p", index="ID", 
           data=subset(data, country=="UK" & lrcat=="right"))
lr2.ruk.coef <- coeftest(lr2.ruk, vcov=vcovHC(lr2.ruk, type="HC0", cluster="group"))  
lr2.ruk.frame=ctdf(lr2.ruk.coef) 

data$c.party3 <- relevel(data$c.party3, ref = "Right") 
lr3.ruk <- plm(lr.s ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
           c.child.num + c.heldoffice + as.factor(candidate) , model="p", index="ID", 
           data=subset(data, country=="UK" &  lrcat=="right"))
lr3.ruk.coef <- coeftest(lr3.ruk, vcov=vcovHC(lr3.ruk, type="HC0", cluster="group"))  
lr3.ruk.frame=ctdf(lr3.ruk.coef)

### Table 12

stargazer(lr1.lus.coef, lr1.rus.coef, lr1.luk.coef, lr1.ruk.coef,
          star.cutoffs = c(0.05, 0.01, 0.001),
          type="html", out="TableS12.doc")

# to get N 
stargazer(lr1.lus, lr1.rus, lr1.luk, lr1.ruk,
          star.cutoffs = c(0.05, 0.01, 0.001),
          type="html", out="TableS12-n.doc")

################################################################################

### Figure S6 (left-hand side): Effect of candidate disability on voter support among left-wing and 
    # right-wing voters, moderated by candidates’ party affiliation, for US and UK 

### Note: The code below produces the plots on the left of the figure, Effect on perceived 
  # candidate ideology, from the models from Table 12. The plots on the right are produced
  # from the models in Table 13, below.

### US

t1.labels <- c("Sample", "Party", "Coefficient", "SE")
t1.row1 <- c("Left-wing voters", "No party", lr1.lus.frame[2,1], lr1.lus.frame[2,2] )
t1.row2 <- c("Left-wing voters", "Left party", lr2.lus.frame[2,1], lr2.lus.frame[2,2] )
t1.row3 <- c("Left-wing voters","Right party", lr3.lus.frame[2,1], lr3.lus.frame[2,2] )
t1.row4 <- c("Right-wing voters", "No party", lr1.rus.frame[2,1], lr1.rus.frame[2,2] )
t1.row5 <- c("Right-wing voters", "Left party", lr2.rus.frame[2,1], lr2.rus.frame[2,2] )
t1.row6 <- c("Right-wing voters","Right party", lr3.rus.frame[2,1], lr3.rus.frame[2,2] )

t1 <- data.frame(rbind(t1.row1,t1.row2,t1.row3,t1.row4,t1.row5,t1.row6))
names(t1) <- t1.labels
t1$Coefficient <- as.numeric(as.character(t1$Coefficient))
t1$SE <- as.numeric(as.character(t1$SE))
t1$Party <- factor(t1$Party, levels = c("Right party", "Left party", "No party"))

interval <- 1.96  # 95% multiplier
plot <- ggplot(t1, aes(shape = Sample))
plot <- plot + geom_hline(yintercept = 0, colour = gray(1/2), lty = 2)
plot <- plot + geom_pointrange(aes(x = Party, y = Coefficient, ymin = Coefficient - SE*interval,
                                   ymax = Coefficient + SE*interval, colour=Sample),
                               lwd = 1/2, shape=20, position = position_dodge(width = 1/2),
                               fill = "WHITE")
plot <- plot +  theme_bw() + ggtitle("Effect on perceived candidate ideology") +
  xlab(" ") + ylab("Conditional AMCE of disability") + ylim(-0.1, 0.1) + coord_flip()
print(plot + scale_colour_manual(name="Sample", values = c("black", "gray45", "gray80")))
ggsave("FigS6a-US.png", dpi=300)

### UK

t1.labels <- c("Sample", "Party", "Coefficient", "SE")
t1.row1 <- c("Left-wing voters", "No party", lr1.luk.frame[2,1], lr1.luk.frame[2,2] )
t1.row2 <- c("Left-wing voters", "Left party", lr2.luk.frame[2,1], lr2.luk.frame[2,2] )
t1.row3 <- c("Left-wing voters","Right party", lr3.luk.frame[2,1], lr3.luk.frame[2,2] )
t1.row4 <- c("Right-wing voters", "No party", lr1.ruk.frame[2,1], lr1.ruk.frame[2,2] )
t1.row5 <- c("Right-wing voters", "Left party", lr2.ruk.frame[2,1], lr2.ruk.frame[2,2] )
t1.row6 <- c("Right-wing voters","Right party", lr3.ruk.frame[2,1], lr3.ruk.frame[2,2] )

t1 <- data.frame(rbind(t1.row1,t1.row2,t1.row3,t1.row4,t1.row5,t1.row6))
names(t1) <- t1.labels
t1$Coefficient <- as.numeric(as.character(t1$Coefficient))
t1$SE <- as.numeric(as.character(t1$SE))
t1$Party <- factor(t1$Party, levels = c("Right party", "Left party", "No party"))

interval <- 1.96  # 95% multiplier
plot <- ggplot(t1, aes(shape = Sample))
plot <- plot + geom_hline(yintercept = 0, colour = gray(1/2), lty = 2)
plot <- plot + geom_pointrange(aes(x = Party, y = Coefficient, ymin = Coefficient - SE*interval,
                                   ymax = Coefficient + SE*interval, colour=Sample),
                               lwd = 1/2, shape=20, position = position_dodge(width = 1/2),
                               fill = "WHITE")
plot <- plot +  theme_bw() + ggtitle("Effect on perceived candidate ideology") +
  xlab(" ") + ylab("Conditional AMCE of disability") + ylim(-0.1, 0.1) + coord_flip()
print(plot + scale_colour_manual(name="Sample", values = c("black", "gray45", "gray80")))
ggsave("FigS6a-UK.png", dpi=300)

################################################################################
################################################################################

### Table S13: Effects of candidate disability on voter support, interacted with 
    # party affiliation treatment, US and UK separately

# Model 1: US; left-wing voters

# These are the estimates in the table:
data$c.party3 <- relevel(data$c.party3, ref = "No party") 
vote.us.l1 <- plm(vote.n ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
              c.child.num + c.heldoffice + as.factor(candidate) , 
              model="p", index="ID", data=subset(data, country=="US" & lrcat=="left"))
vote.us.l1.coef <- coeftest(vote.us.l1, vcov=vcovHC(vote.us.l1, type="HC0", cluster="group"))  
vote.us.l1.frame=ctdf(vote.us.l1.coef) 

data$c.party3 <- relevel(data$c.party3, ref = "Left")
vote.us.l2 <- plm(vote.n ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
              c.child.num + c.heldoffice + as.factor(candidate) , 
              model="p", index="ID", data=subset(data, country=="US" & lrcat=="left"))
vote.us.l2.coef <- coeftest(vote.us.l2, vcov=vcovHC(vote.us.l2, type="HC0", cluster="group"))  
vote.us.l2.frame=ctdf(vote.us.l2.coef)

data$c.party3 <- relevel(data$c.party3, ref = "Right") 
vote.us.l3 <- plm(vote.n ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
              c.child.num + c.heldoffice + as.factor(candidate) , 
              model="p", index="ID", data=subset(data, country=="US" & lrcat=="left"))
vote.us.l3.coef <- coeftest(vote.us.l3, vcov=vcovHC(vote.us.l3, type="HC0", cluster="group"))  
vote.us.l3.frame=ctdf(vote.us.l3.coef)

### Model 2: US; right-wing voters

# These are the estimates in the table:
data$c.party3 <- relevel(data$c.party3, ref = "No party")
vote.us.r1 <- plm(vote.n ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
              c.child.num + c.heldoffice + as.factor(candidate) , 
              model="p", index="ID", data=subset(data, country=="US" & lrcat=="right"))
vote.us.r1.coef <- coeftest(vote.us.r1, vcov=vcovHC(vote.us.r1, type="HC0", cluster="group"))  
vote.us.r1.frame=ctdf(vote.us.r1.coef) 

data$c.party3 <- relevel(data$c.party3, ref = "Left") 
vote.us.r2 <- plm(vote.n ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
              c.child.num + c.heldoffice + as.factor(candidate) , 
              model="p", index="ID", data=subset(data, country=="US" & lrcat=="right"))
vote.us.r2.coef <- coeftest(vote.us.r2, vcov=vcovHC(vote.us.r2, type="HC0", cluster="group"))  
vote.us.r2.frame=ctdf(vote.us.r2.coef)

data$c.party3 <- relevel(data$c.party3, ref = "Right")
vote.us.r3 <- plm(vote.n ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
              c.child.num + c.heldoffice + as.factor(candidate) , 
              model="p", index="ID", data=subset(data, country=="US" & lrcat=="right"))
vote.us.r3.coef <- coeftest(vote.us.r3, vcov=vcovHC(vote.us.r3, type="HC0", cluster="group"))  
vote.us.r3.frame=ctdf(vote.us.r3.coef)

### Model 3: UK; left-wing voters

# These are the estimates in the table:
data$c.party3 <- relevel(data$c.party3, ref = "No party") 
vote.uk.l1 <- plm(vote.n ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
              c.child.num + c.heldoffice + as.factor(candidate) , 
              model="p", index="ID", data=subset(data, country=="UK" & lrcat=="left"))
vote.uk.l1.coef <- coeftest(vote.uk.l1, vcov=vcovHC(vote.uk.l1, type="HC0", cluster="group"))  
vote.uk.l1.frame=ctdf(vote.uk.l1.coef) 

data$c.party3 <- relevel(data$c.party3, ref = "Left") 
vote.uk.l2 <- plm(vote.n ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
              c.child.num + c.heldoffice + as.factor(candidate) , 
              model="p", index="ID", data=subset(data, country=="UK" & lrcat=="left"))
vote.uk.l2.coef <- coeftest(vote.uk.l2, vcov=vcovHC(vote.uk.l2, type="HC0", cluster="group"))  
vote.uk.l2.frame=ctdf(vote.uk.l2.coef)

data$c.party3 <- relevel(data$c.party3, ref = "Right") 
vote.uk.l3 <- plm(vote.n ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
              c.child.num + c.heldoffice + as.factor(candidate) , 
              model="p", index="ID", data=subset(data, country=="UK" & lrcat=="left"))
vote.uk.l3.coef <- coeftest(vote.uk.l3, vcov=vcovHC(vote.uk.l3, type="HC0", cluster="group"))  
vote.uk.l3.frame=ctdf(vote.uk.l3.coef)

# Model 4: UK; right-wing voters

# These are the estimates in the table: 
data$c.party3 <- relevel(data$c.party3, ref = "No party") 
vote.uk.r1 <- plm(vote.n ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
              c.child.num + c.heldoffice + as.factor(candidate) , 
              model="p", index="ID", data=subset(data, country=="UK" & lrcat=="right"))
vote.uk.r1.coef <- coeftest(vote.uk.r1, vcov=vcovHC(vote.uk.r1, type="HC0", cluster="group"))  
vote.uk.r1.frame=ctdf(vote.uk.r1.coef) 

data$c.party3 <- relevel(data$c.party3, ref = "Left")
vote.uk.r2 <- plm(vote.n ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
              c.child.num + c.heldoffice + as.factor(candidate) , 
              model="p", index="ID", data=subset(data, country=="UK" & lrcat=="right"))
vote.uk.r2.coef <- coeftest(vote.uk.r2, vcov=vcovHC(vote.uk.r2, type="HC0", cluster="group"))  
vote.uk.r2.frame=ctdf(vote.uk.r2.coef)

data$c.party3 <- relevel(data$c.party3, ref = "Right") 
vote.uk.r3 <- plm(vote.n ~ c.disdummy*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
              c.child.num + c.heldoffice + as.factor(candidate) , 
              model="p", index="ID", data=subset(data, country=="UK" & lrcat=="right"))
vote.uk.r3.coef <- coeftest(vote.uk.r3, vcov=vcovHC(vote.uk.r3, type="HC0", cluster="group"))  
vote.uk.r3.frame=ctdf(vote.uk.r3.coef)

### Table S13

stargazer(vote.us.l1.coef, vote.us.r1.coef, vote.uk.l1.coef, vote.uk.r1.coef,
          star.cutoffs = c(0.05, 0.01, 0.001),
          type="html", out="tableS13.doc")

# to get the N
stargazer(vote.us.l1, vote.us.r1, vote.uk.l1, vote.uk.r1,
          star.cutoffs = c(0.05, 0.01, 0.001),
          type="html", out="tableS13-n.doc")

################################################################################

### Figure S6 (right-hand side)

### Note: The code below produces the plots on the left of the figure, Effect on perceived 
# candidate ideology, from the models from Table 12. The plots on the right are produced
# from the models in Table 13, below.

### US

t1.labels <- c("Sample", "Party", "Coefficient", "SE")
t1.row1 <- c("Left-wing voters", "No party", vote.us.l1.frame[2,1], vote.us.l1.frame[2,2] )
t1.row2 <- c("Left-wing voters", "Left party", vote.us.l2.frame[2,1], vote.us.l2.frame[2,2] )
t1.row3 <- c("Left-wing voters","Right party", vote.us.l3.frame[2,1], vote.us.l3.frame[2,2] )
t1.row4 <- c("Right-wing voters", "No party", vote.us.r1.frame[2,1], vote.us.r1.frame[2,2] )
t1.row5 <- c("Right-wing voters", "Left party", vote.us.r2.frame[2,1], vote.us.r2.frame[2,2] )
t1.row6 <- c("Right-wing voters","Right party", vote.us.r3.frame[2,1], vote.us.r3.frame[2,2] )

t1 <- data.frame(rbind(t1.row1,t1.row2,t1.row3,t1.row4,t1.row5,t1.row6))
names(t1) <- t1.labels
t1$Coefficient <- as.numeric(as.character(t1$Coefficient))
t1$SE <- as.numeric(as.character(t1$SE))
t1$Party <- factor(t1$Party, levels = c("Right party", "Left party", "No party"))

interval <- 1.96  # 95% multiplier
plot <- ggplot(t1, aes(shape = Sample))
plot <- plot + geom_hline(yintercept = 0, colour = gray(1/2), lty = 2)
plot <- plot + geom_pointrange(aes(x = Party, y = Coefficient, ymin = Coefficient - SE*interval,
                                   ymax = Coefficient + SE*interval, colour=Sample),
                               lwd = 1/2, shape=20, position = position_dodge(width = 1/2),
                               fill = "WHITE")
plot <- plot +  theme_bw() + ggtitle("Effect on candidate support") +
  xlab(" ") + ylab("Conditional AMCE of disability") + ylim(-0.15, 0.15) + coord_flip()
print(plot + scale_colour_manual(name="Sample", values = c("black", "gray45", "gray80")))
ggsave("FigS6b-US.png", dpi=300)

### UK

t1.labels <- c("Sample", "Party", "Coefficient", "SE")
t1.row1 <- c("Left-wing voters", "No party", vote.uk.l1.frame[2,1], vote.uk.l1.frame[2,2] )
t1.row2 <- c("Left-wing voters", "Left party", vote.uk.l2.frame[2,1], vote.uk.l2.frame[2,2] )
t1.row3 <- c("Left-wing voters","Right party", vote.uk.l3.frame[2,1], vote.uk.l3.frame[2,2] )
t1.row4 <- c("Right-wing voters", "No party", vote.uk.r1.frame[2,1], vote.uk.r1.frame[2,2] )
t1.row5 <- c("Right-wing voters", "Left party", vote.uk.r2.frame[2,1], vote.uk.r2.frame[2,2] )
t1.row6 <- c("Right-wing voters","Right party", vote.uk.r3.frame[2,1], vote.uk.r3.frame[2,2] )

t1 <- data.frame(rbind(t1.row1,t1.row2,t1.row3,t1.row4,t1.row5,t1.row6))
names(t1) <- t1.labels
t1$Coefficient <- as.numeric(as.character(t1$Coefficient))
t1$SE <- as.numeric(as.character(t1$SE))
t1$Party <- factor(t1$Party, levels = c("Right party", "Left party", "No party"))

plot <- ggplot(t1, aes(shape = Sample))
plot <- plot + geom_hline(yintercept = 0, colour = gray(1/2), lty = 2)
plot <- plot + geom_pointrange(aes(x = Party, y = Coefficient, ymin = Coefficient - SE*interval,
                                   ymax = Coefficient + SE*interval, colour=Sample),
                               lwd = 1/2, shape=20, position = position_dodge(width = 1/2),
                               fill = "WHITE")
plot <- plot +  theme_bw() + ggtitle("Effect on candidate support") +
  xlab(" ") + ylab("Conditional AMCE of disability") + ylim(-0.15, 0.18) + coord_flip()
print(plot + scale_colour_manual(name="Sample", values = c("black", "gray45", "gray80")))
ggsave("FigS6b-UK.png", dpi=300)

################################################################################
################################################################################

### Analysis by disability type

### Table S14: Effects of three candidate disability types on perceived candidate 
    # ideology and voter support, interacted with party affiliation treatment 

### Model 1: Left-wing voters; DV: perceived ideology

# These are the estimates in the table:
data$c.party3 <- relevel(data$c.party3, ref = "No party") 
lr1.l <- plm(lr.s ~ c.dis*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
         c.child.num + c.heldoffice + as.factor(candidate) + country, model="p", index="ID", 
         data=subset(data, lrcat=="left"))
lr1.l.coef <- coeftest(lr1.l, vcov=vcovHC(lr1.l, type="HC0", cluster="group"))  
lr1.l.frame=ctdf(lr1.l.coef)  
lr1.l.frame

data$c.party3 <- relevel(data$c.party3, ref = "Left") 
lr2.l <- plm(lr.s ~ c.dis*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
         c.child.num + c.heldoffice + as.factor(candidate) + country, model="p", index="ID", 
         data=subset(data, lrcat=="left"))
lr2.l.coef <- coeftest(lr2.l, vcov=vcovHC(lr2.l, type="HC0", cluster="group"))  
lr2.l.frame=ctdf(lr2.l.coef) 

data$c.party3 <- relevel(data$c.party3, ref = "Right") 
lr3.l <- plm(lr.s ~ c.dis*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
         c.child.num + c.heldoffice + as.factor(candidate) + country, model="p", index="ID", 
         data=subset(data, lrcat=="left"))
lr3.l.coef <- coeftest(lr3.l, vcov=vcovHC(lr3.l, type="HC0", cluster="group"))  
lr3.l.frame=ctdf(lr3.l.coef) 

### Model 2: Right-wing voters; DV: perceived ideology

# These are the estimates in the table:
data$c.party3 <- relevel(data$c.party3, ref = "No party") 
lr1.r <- plm(lr.s ~ c.dis*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
         c.child.num + c.heldoffice + as.factor(candidate) + country, model="p", index="ID", 
         data=subset(data, lrcat=="right"))
lr1.r.coef <- coeftest(lr1.r, vcov=vcovHC(lr1.r, type="HC0", cluster="group"))  
lr1.r.frame=ctdf(lr1.r.coef) # Model for Table S14

data$c.party3 <- relevel(data$c.party3, ref = "Left") 
lr2.r <- plm(lr.s ~ c.dis*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
         c.child.num + c.heldoffice + as.factor(candidate) + country, model="p", index="ID", 
         data=subset(data, lrcat=="right"))
lr2.r.coef <- coeftest(lr2.r, vcov=vcovHC(lr2.r, type="HC0", cluster="group"))  
lr2.r.frame=ctdf(lr2.r.coef) 

data$c.party3 <- relevel(data$c.party3, ref = "Right")
lr3.r <- plm(lr.s ~ c.dis*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
         c.child.num + c.heldoffice + as.factor(candidate) + country, model="p", index="ID", 
         data=subset(data, lrcat=="right"))
lr3.r.coef <- coeftest(lr3.r, vcov=vcovHC(lr3.r, type="HC0", cluster="group"))  
lr3.r.frame=ctdf(lr3.r.coef) 

### Model 3: Left-wing voters; DV: voter support

# These are the estimates in the table:
data$c.party3 <- relevel(data$c.party3, ref = "No party") 
vote.l1 <- plm(vote.n ~ c.dis*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
           c.child.num + c.heldoffice + as.factor(candidate) + country, 
           model="p", index="ID", data=subset(data, lrcat=="left"))
vote.l1.coef <- coeftest(vote.l1, vcov=vcovHC(vote.l1, type="HC0", cluster="group"))  
vote.l1.frame=ctdf(vote.l1.coef) 

data$c.party3 <- relevel(data$c.party3, ref = "Left") 
vote.l2 <- plm(vote.n ~ c.dis*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
           c.child.num + c.heldoffice + as.factor(candidate) + country, 
           model="p", index="ID", data=subset(data, lrcat=="left"))
vote.l2.coef <- coeftest(vote.l2, vcov=vcovHC(vote.l2, type="HC0", cluster="group"))  
vote.l2.frame=ctdf(vote.l2.coef)

data$c.party3 <- relevel(data$c.party3, ref = "Right") 
vote.l3 <- plm(vote.n ~ c.dis*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
           c.child.num + c.heldoffice + as.factor(candidate) + country, 
           model="p", index="ID", data=subset(data, lrcat=="left"))
vote.l3.coef <- coeftest(vote.l3, vcov=vcovHC(vote.l3, type="HC0", cluster="group"))  
vote.l3.frame=ctdf(vote.l3.coef)

### Model 4: Right-wing voters; DV: voter support

# These are the estimates in the table:
data$c.party3 <- relevel(data$c.party3, ref = "No party") 
vote.r1 <- plm(vote.n ~ c.dis*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
           c.child.num + c.heldoffice + as.factor(candidate) + country, 
           model="p", index="ID", data=subset(data, lrcat=="right"))
vote.r1.coef <- coeftest(vote.r1, vcov=vcovHC(vote.r1, type="HC0", cluster="group"))  
vote.r1.frame=ctdf(vote.r1.coef) 

data$c.party3 <- relevel(data$c.party3, ref = "Left") 
vote.r2 <- plm(vote.n ~ c.dis*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
           c.child.num + c.heldoffice + as.factor(candidate) + country, 
           model="p", index="ID", data=subset(data, lrcat=="right"))
vote.r2.coef <- coeftest(vote.r2, vcov=vcovHC(vote.r2, type="HC0", cluster="group"))  
vote.r2.frame=ctdf(vote.r2.coef)

data$c.party3 <- relevel(data$c.party3, ref = "Right") 
vote.r3 <- plm(vote.n ~ c.dis*c.party3 + c.age + c.female + c.minority + c.job + c.exp + 
           c.child.num + c.heldoffice + as.factor(candidate) + country, 
           model="p", index="ID", data=subset(data, lrcat=="right"))
vote.r3.coef <- coeftest(vote.r3, vcov=vcovHC(vote.r3, type="HC0", cluster="group"))  
vote.r3.frame=ctdf(vote.r3.coef)

################################################################################

### Table S14

stargazer(lr1.l.coef, lr1.r.coef, vote.l1.coef, vote.r1.coef,
          star.cutoffs = c(0.05, 0.01, 0.001),
          type="html", out="TableS14.doc")

# to get N
stargazer(lr1.l, lr1.r,vote.l1, vote.r1,
          star.cutoffs = c(0.05, 0.01, 0.001),
          type="html", out="TableS14-n.doc")

################################################################################

### Figure S7: Effect of three candidate disability types on voter support among 
    # left-wing and right-wing voters, moderated by candidates’ party affiliation

### Blind candidate

# Ideology (left-hand figure)

t1.labels <- c("Sample", "Party", "Coefficient", "SE")
t1.row1 <- c("Left-wing voters", "No party", lr1.l.frame[2,1], lr1.l.frame[2,2] )
t1.row2 <- c("Left-wing voters", "Left party", lr2.l.frame[2,1], lr2.l.frame[2,2] )
t1.row3 <- c("Left-wing voters","Right party", lr3.l.frame[2,1], lr3.l.frame[2,2] )
t1.row4 <- c("Right-wing voters", "No party", lr1.r.frame[2,1], lr1.r.frame[2,2] )
t1.row5 <- c("Right-wing voters", "Left party", lr2.r.frame[2,1], lr2.r.frame[2,2] )
t1.row6 <- c("Right-wing voters","Right party", lr3.r.frame[2,1], lr3.r.frame[2,2] )

t1 <- data.frame(rbind(t1.row1,t1.row2,t1.row3,t1.row4,t1.row5,t1.row6))
names(t1) <- t1.labels
t1$Coefficient <- as.numeric(as.character(t1$Coefficient))
t1$SE <- as.numeric(as.character(t1$SE))
t1$Party <- factor(t1$Party, levels = c("Right party", "Left party", "No party"))

plot <- ggplot(t1, aes(shape = Sample))
plot <- plot + geom_hline(yintercept = 0, colour = gray(1/2), lty = 2)
plot <- plot + geom_pointrange(aes(x = Party, y = Coefficient, ymin = Coefficient - SE*interval,
                                   ymax = Coefficient + SE*interval, colour=Sample),
                               lwd = 1/2, shape=20, position = position_dodge(width = 1/2),
                               fill = "WHITE")
plot <- plot +  theme_bw() + ggtitle("Effect on perceived candidate ideology") +
  xlab(" ") + ylab("Conditional AMCE of disability") + ylim(-0.1, 0.1) + coord_flip()
print(plot + scale_colour_manual(name="Sample", values = c("black", "gray45", "gray80")))
ggsave("FigS7a-blind.png", dpi=300)

# Support (right-hand figure)

t1.labels <- c("Sample", "Party", "Coefficient", "SE")
t1.row1 <- c("Left-wing voters", "No party", vote.l1.frame[2,1], vote.l1.frame[2,2] )
t1.row2 <- c("Left-wing voters", "Left party", vote.l2.frame[2,1], vote.l2.frame[2,2] )
t1.row3 <- c("Left-wing voters","Right party", vote.l3.frame[2,1], vote.l3.frame[2,2] )
t1.row4 <- c("Right-wing voters", "No party", vote.r1.frame[2,1], vote.r1.frame[2,2] )
t1.row5 <- c("Right-wing voters", "Left party", vote.r2.frame[2,1], vote.r2.frame[2,2] )
t1.row6 <- c("Right-wing voters","Right party", vote.r3.frame[2,1], vote.r3.frame[2,2] )

t1 <- data.frame(rbind(t1.row1,t1.row2,t1.row3,t1.row4,t1.row5,t1.row6))
names(t1) <- t1.labels
t1$Coefficient <- as.numeric(as.character(t1$Coefficient))
t1$SE <- as.numeric(as.character(t1$SE))
t1$Party <- factor(t1$Party, levels = c("Right party", "Left party", "No party"))

plot <- ggplot(t1, aes(shape = Sample))
plot <- plot + geom_hline(yintercept = 0, colour = gray(1/2), lty = 2)
plot <- plot + geom_pointrange(aes(x = Party, y = Coefficient, ymin = Coefficient - SE*interval,
                                   ymax = Coefficient + SE*interval, colour=Sample),
                               lwd = 1/2, shape=20, position = position_dodge(width = 1/2),
                               fill = "WHITE")
plot <- plot +  theme_bw() + ggtitle("Effect on candidate support") +
  xlab(" ") + ylab("Conditional AMCE of disability") + ylim(-0.15, 0.15) + coord_flip()
print(plot + scale_colour_manual(name="Sample", values = c("black", "gray45", "gray80")))
ggsave("FigS7b-blind.png", dpi=300)

### Deaf candidate

# Ideology (left-hand figure)

t1.labels <- c("Sample", "Party", "Coefficient", "SE")
t1.row1 <- c("Left-wing voters", "No party", lr1.l.frame[3,1], lr1.l.frame[3,2] )
t1.row2 <- c("Left-wing voters", "Left party", lr2.l.frame[3,1], lr2.l.frame[3,2] )
t1.row3 <- c("Left-wing voters","Right party", lr3.l.frame[3,1], lr3.l.frame[3,2] )
t1.row4 <- c("Right-wing voters", "No party", lr1.r.frame[3,1], lr1.r.frame[3,2] )
t1.row5 <- c("Right-wing voters", "Left party", lr2.r.frame[3,1], lr2.r.frame[3,2] )
t1.row6 <- c("Right-wing voters","Right party", lr3.r.frame[3,1], lr3.r.frame[3,2] )

t1 <- data.frame(rbind(t1.row1,t1.row2,t1.row3,t1.row4,t1.row5,t1.row6))
names(t1) <- t1.labels
t1$Coefficient <- as.numeric(as.character(t1$Coefficient))
t1$SE <- as.numeric(as.character(t1$SE))
t1$Party <- factor(t1$Party, levels = c("Right party", "Left party", "No party"))

plot <- ggplot(t1, aes(shape = Sample))
plot <- plot + geom_hline(yintercept = 0, colour = gray(1/2), lty = 2)
plot <- plot + geom_pointrange(aes(x = Party, y = Coefficient, ymin = Coefficient - SE*interval,
                                   ymax = Coefficient + SE*interval, colour=Sample),
                               lwd = 1/2, shape=20, position = position_dodge(width = 1/2),
                               fill = "WHITE")
plot <- plot +  theme_bw() + ggtitle("Effect on perceived candidate ideology") +
  xlab(" ") + ylab("Conditional AMCE of disability") + ylim(-0.1, 0.1) + coord_flip()
print(plot + scale_colour_manual(name="Sample", values = c("black", "gray45", "gray80")))
ggsave("FigS7a-deaf.png", dpi=300)

# Support (right-hand figure)

t1.labels <- c("Sample", "Party", "Coefficient", "SE")
t1.row1 <- c("Left-wing voters", "No party", vote.l1.frame[3,1], vote.l1.frame[3,2] )
t1.row2 <- c("Left-wing voters", "Left party", vote.l2.frame[3,1], vote.l2.frame[3,2] )
t1.row3 <- c("Left-wing voters","Right party", vote.l3.frame[3,1], vote.l3.frame[3,2] )
t1.row4 <- c("Right-wing voters", "No party", vote.r1.frame[3,1], vote.r1.frame[3,2] )
t1.row5 <- c("Right-wing voters", "Left party", vote.r2.frame[3,1], vote.r2.frame[3,2] )
t1.row6 <- c("Right-wing voters","Right party", vote.r3.frame[3,1], vote.r3.frame[3,2] )

t1 <- data.frame(rbind(t1.row1,t1.row2,t1.row3,t1.row4,t1.row5,t1.row6))
names(t1) <- t1.labels
t1$Coefficient <- as.numeric(as.character(t1$Coefficient))
t1$SE <- as.numeric(as.character(t1$SE))
t1$Party <- factor(t1$Party, levels = c("Right party", "Left party", "No party"))

plot <- ggplot(t1, aes(shape = Sample))
plot <- plot + geom_hline(yintercept = 0, colour = gray(1/2), lty = 2)
plot <- plot + geom_pointrange(aes(x = Party, y = Coefficient, ymin = Coefficient - SE*interval,
                                   ymax = Coefficient + SE*interval, colour=Sample),
                               lwd = 1/2, shape=20, position = position_dodge(width = 1/2),
                               fill = "WHITE")
plot <- plot +  theme_bw() + ggtitle("Effect on candidate support") +
  xlab(" ") + ylab("Conditional AMCE of disability") + ylim(-0.15, 0.16) + coord_flip()
print(plot + scale_colour_manual(name="Sample", values = c("black", "gray45", "gray80")))
ggsave("FigS7b-deaf.png", dpi=300)

### Paraplegic

# Ideology (left-hand figure)

t1.labels <- c("Sample", "Party", "Coefficient", "SE")
t1.row1 <- c("Left-wing voters", "No party", lr1.l.frame[4,1], lr1.l.frame[4,2] )
t1.row2 <- c("Left-wing voters", "Left party", lr2.l.frame[4,1], lr2.l.frame[4,2] )
t1.row3 <- c("Left-wing voters","Right party", lr3.l.frame[4,1], lr3.l.frame[4,2] )
t1.row4 <- c("Right-wing voters", "No party", lr1.r.frame[4,1], lr1.r.frame[4,2] )
t1.row5 <- c("Right-wing voters", "Left party", lr2.r.frame[4,1], lr2.r.frame[4,2] )
t1.row6 <- c("Right-wing voters","Right party", lr3.r.frame[4,1], lr3.r.frame[4,2] )

t1 <- data.frame(rbind(t1.row1,t1.row2,t1.row3,t1.row4,t1.row5,t1.row6))
names(t1) <- t1.labels
t1$Coefficient <- as.numeric(as.character(t1$Coefficient))
t1$SE <- as.numeric(as.character(t1$SE))
t1$Party <- factor(t1$Party, levels = c("Right party", "Left party", "No party"))

plot <- ggplot(t1, aes(shape = Sample))
plot <- plot + geom_hline(yintercept = 0, colour = gray(1/2), lty = 2)
plot <- plot + geom_pointrange(aes(x = Party, y = Coefficient, ymin = Coefficient - SE*interval,
                                   ymax = Coefficient + SE*interval, colour=Sample),
                               lwd = 1/2, shape=20, position = position_dodge(width = 1/2),
                               fill = "WHITE")
plot <- plot +  theme_bw() + ggtitle("Effect on perceived candidate ideology") +
  xlab(" ") + ylab("Conditional AMCE of disability") + ylim(-0.1, 0.1) + coord_flip()
print(plot + scale_colour_manual(name="Sample", values = c("black", "gray45", "gray80")))
ggsave("FigS7a-para.png", dpi=300)

# Support (right-hand figure)

t1.labels <- c("Sample", "Party", "Coefficient", "SE")
t1.row1 <- c("Left-wing voters", "No party", vote.l1.frame[4,1], vote.l1.frame[4,2] )
t1.row2 <- c("Left-wing voters", "Left party", vote.l2.frame[4,1], vote.l2.frame[4,2] )
t1.row3 <- c("Left-wing voters","Right party", vote.l3.frame[4,1], vote.l3.frame[4,2] )
t1.row4 <- c("Right-wing voters", "No party", vote.r1.frame[4,1], vote.r1.frame[4,2] )
t1.row5 <- c("Right-wing voters", "Left party", vote.r2.frame[4,1], vote.r2.frame[4,2] )
t1.row6 <- c("Right-wing voters","Right party", vote.r3.frame[4,1], vote.r3.frame[4,2] )

t1 <- data.frame(rbind(t1.row1,t1.row2,t1.row3,t1.row4,t1.row5,t1.row6))
names(t1) <- t1.labels
t1$Coefficient <- as.numeric(as.character(t1$Coefficient))
t1$SE <- as.numeric(as.character(t1$SE))
t1$Party <- factor(t1$Party, levels = c("Right party", "Left party", "No party"))

plot <- ggplot(t1, aes(shape = Sample))
plot <- plot + geom_hline(yintercept = 0, colour = gray(1/2), lty = 2)
plot <- plot + geom_pointrange(aes(x = Party, y = Coefficient, ymin = Coefficient - SE*interval,
                                   ymax = Coefficient + SE*interval, colour=Sample),
                               lwd = 1/2, shape=20, position = position_dodge(width = 1/2),
                               fill = "WHITE")
plot <- plot +  theme_bw() + ggtitle("Effect on candidate support") +
  xlab(" ") + ylab("Conditional AMCE of disability") + ylim(-0.15, 0.16) + coord_flip()
print(plot + scale_colour_manual(name="Sample", values = c("black", "gray45", "gray80")))
ggsave("FigS7b-para.png", dpi=300)

########################################################################################
########################################################################################
########################################################################################

### SI 6: Mediation analysis: effect of candidate disability on left-wing voters’ 
    # support of candidates of left-wing parties, mediated by candidates’ perceived 
    # ability to represent under-represented groups

### Tables S15 and S16

### Model 1
med.fit <- lm(represent.n ~ c.disdummy + c.age + c.female + c.minority + c.job + c.exp + 
           c.child.num + c.heldoffice + as.factor(candidate) + country, 
           data=subset(data, c.party3=="Left" & !is.na(vote.n) & lrcat=="left"))
summary(med.fit)

### Model 2
out.fit.lm <- lm(vote.n ~ represent.n + c.disdummy + c.age + c.female + c.minority + c.job + c.exp + 
              c.child.num + c.heldoffice + as.factor(candidate) + country,  
              data=subset(data, c.party3=="Left" & lrcat=="left"))
summary(out.fit.lm)

### Model 3: logit
out.fit.ln <- glm(vote.n ~ represent.n + c.disdummy + c.age + c.female + c.minority + c.job + c.exp + 
              c.child.num + c.heldoffice + as.factor(candidate) + country,  
              data=subset(data, c.party3=="Left" & lrcat=="left"), family = binomial('logit'))
summary(out.fit.ln)

### Table S15

stargazer(med.fit, out.fit.lm, out.fit.ln,
          star.cutoffs = c(0.05, 0.01, 0.001),
          type="html", out="TableS15.doc")

### Mediation analysis: the results must be entered manually into Table S16

### Linear model
med.out.lm <- mediate(med.fit, out.fit.lm, treat = "c.disdummy", mediator = "represent.n",
              robustSE = T, sims = 10000)
summary(med.out.lm)

### Logit model
med.out.ln <- mediate(med.fit, out.fit.ln, treat = "c.disdummy", mediator = "represent.n",
              robustSE = T, sims = 10000)
summary(med.out.ln)

################################################################################

### Figure S8: sensitivity analysis 

sens.out <- medsens(med.out.lm, rho.by = 0.1, effect.type = "indirect", sims = 100)
summary(sens.out)
png(file="FigS8.png")
plot(sens.out, sens.par = "rho", main = " ", ylim = c(-0.2, 0.2))
dev.off()

################################################################################
################################################################################
################################################################################

### SI 7: Effects of candidate disability on voter support across all voters in 
  # experiment with party information

### Table S17: Effects of candidate disability on voter support in experiment with 
    # party information

### Model 1: UK and US

vote.m1 <- plm(vote.n ~ c.disdummy + c.age + c.female + c.minority + c.job + c.exp + 
           c.child.num + c.heldoffice + c.party + as.factor(candidate) , model="p", index="ID", 
           data=subset(data, !is.na(c.party)))
vote.m1.coef <- coeftest(vote.m1, vcov=vcovHC(vote.m1, type="HC0", cluster="group"))  

### Model 2: US

vote.m1us <- plm(vote.n ~ c.disdummy + c.age + c.female + c.minority + c.job + c.exp + 
             c.child.num + c.heldoffice + c.party + as.factor(candidate), model="p", index="ID", 
             data=subset(data, !is.na(c.party) & country=="US"))
vote.m1us.coef <- coeftest(vote.m1us, vcov=vcovHC(vote.m1us, type="HC0", cluster="group"))  

### Model 3: UK 

vote.m1uk <- plm(vote.n ~ c.disdummy + c.age + c.female + c.minority + c.job + c.exp + 
             c.child.num + c.heldoffice + c.party + as.factor(candidate), model="p", index="ID", 
             data=subset(data, !is.na(c.party) & country=="UK"))
vote.m1uk.coef <- coeftest(vote.m1uk, vcov=vcovHC(vote.m1uk, type="HC0", cluster="group"))  

### Model 4: US and UK, 4-category disability measure 

data$c.dis <- relevel(data$c.dis, ref="None")
vote.m1.d <- plm(vote.n ~ c.dis + c.age + c.female + c.minority + c.job + c.exp + 
             c.child.num + c.heldoffice + c.party + as.factor(candidate) , model="p", index="ID", 
             data=subset(data, !is.na(c.party)))
vote.m1.d.coef <- coeftest(vote.m1.d, vcov=vcovHC(vote.m1.d, type="HC0", cluster="group"))  

### Table S17

stargazer(vote.m1.coef, vote.m1us.coef, vote.m1uk.coef, vote.m1.d.coef,
          star.cutoffs = c(0.05, 0.01, 0.001),
          type="html", out="TableS17.doc")

# to get the N for each model: 
stargazer(vote.m1, vote.m1us, vote.m1uk, vote.m1.d,
          star.cutoffs = c(0.05, 0.01, 0.001),
          type="html", out="TableS17-n.doc")






